/**
 * Date:2022年1月6日 上午10:16:18
 * Copyright (c) 2022, www.bwbroad.com All Rights Reserved
 */

package com.app.common.utils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;

/**
 * Description: TODO <br/>
 * Date:2022年1月6日 上午10:16:18 <br/>
 * 
 * @author xuejianxin
 */
public class BeanUtilsX {
	static {
		ConvertUtils.register(new DebeziumDateConvert(), java.util.Date.class);
	}

	// 支持map 拷贝到bean
	public static void copyProperties(Object dest, Object orig) {
		try {
			BeanUtils.copyProperties(dest, orig);
		} catch (IllegalAccessException ex) {
			ex.printStackTrace();
		} catch (InvocationTargetException ex) {
			ex.printStackTrace();
		}
	}

	// map 拷贝到bean,spring 自带的BeanUtils 不支持map 到bean拷贝
	public static void mapToBean(Object dest, final Map<String, ? extends Object> properties) {
		try {
			BeanUtils.populate(dest, properties);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}

	}

}
